//
//  SingleExE.m
//  Unicorn
//
//  Created by xalo on 16/4/29.
//  Copyright © 2016年 bhj_jun. All rights reserved.
//

#import "SingleExE.h"

@implementation SingleExE

+(SingleExE *)sharedHandle
{
    static SingleExE *handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        handle = [[SingleExE alloc]init];
    });
    return handle;
}

-(UIButton *)setButtonWithTitle:(NSString *)title frame:(CGRect)frame
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.frame = frame;
    return btn;
    
}


+ (void)postFetchDataWithUrlString:(NSString *)urlStr paramenters:(NSDictionary *)parameters success:(void (^)(id))success fail:(void (^)())fail view:(UIView *)view {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    MBProgressHUD *mb = [MBProgressHUD showHUDAddedTo:view animated:YES];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        [manager POST:urlStr parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [mb removeFromSuperview];
            });
            if (success) {
                
                success(responseObject);
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [mb removeFromSuperview];
            });
            if (fail) {
                
                fail();
            }
            
        }];
        
    });

}


@end
